#ifdef GL_ES
precision mediump float;  
#endif

const vec2 bitShift = vec2( 256.0, 1.0);
const vec2 bitMask = vec2(0.0, 1.0 / 256.0);
varying vec3 pos;
varying float v_depth;
varying vec3 v_normal;

void main() {		 
	vec2 comp = fract(vec2(v_depth) * bitShift);
	gl_FragColor.rg = vec2(comp - comp.xx * bitMask); //this give more precission	
	
	//normal spheremapped
	vec3 normal = normalize(v_normal);
	gl_FragColor.zw =  vec2((normal.xy * inversesqrt(normal.z*8.0+8.0))+0.5);
	//normal (z^2 + x^2 + y^2) = 1
	//gl_FragColor.zw =(normal).rg * 0.5 +0.5;
	
	
}